/**
 * Copyright (c) 2009 Teoti Graphix, LLC See:
 *     http://tkarchitecture.teotigraphix.org
 * 
 * Permission is hereby granted, free of charge, to any person
 * obtaining a copy of this software and associated documentation
 * files (the "Software"), to deal in the Software without
 * restriction, including without limitation the rights to use,
 * copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the
 * Software is furnished to do so, subject to the following
 * conditions:
 * 
 * The above copyright notice and this permission notice shall be
 * included in all copies or substantial portions of the Software.
 * 
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
 * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
 * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
 * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
 * OTHER DEALINGS IN THE SOFTWARE.
 * 
 * @author Michael Schmalle mschmalle@teotigraphix.com
 */
package org.example.ui.behavior
{

import flash.events.MouseEvent;

import mx.core.UIComponent;

import org.teotigraphix.tka.patterns.behavior.SparkComponentBehavior;

import spark.components.TextInput;
import spark.components.supportClasses.TextBase;

//--------------------------------------
//  ComponentHandler
//--------------------------------------

[ComponentHandler(event="rollOver", handler="rollOverHandler")]
[ComponentHandler(event="rollOut", handler="rollOutHandler")]

/**
 * The HelloWorld behavior of the TKA framework.
 * 
 * <p>This behavior shows how it's possible to write a behvior that can 
 * expect more than one type of skin part or component host.</p>
 * 
 * <p>Behavior;</p>
 * <ul>
 * <li>Alias a Button's labelDisplay part.</li>
 * <li>Alias a TextInput's textDisplay part.</li>
 * <li>Handle ROLL_OVER event from component.</li>
 * <li>Handle ROLL_OUT event from component.</li>
 * <li>Change component's text property depending on ROLL_OUT or ROLL_OVER.</li>
 * </ul>
 * 
 * @author Michael Schmalle
 * @date 08-07-09
 */
public class HelloWorldBehavior 
	   extends SparkComponentBehavior
{
	//--------------------------------------------------------------------------
	//
	//  ComponentAlias :: Variables
	//
	//--------------------------------------------------------------------------
		
	[ComponentAlias]
	
	/**
	 * The element cast to a UIComponent.
	 * 
	 * <p>If element is not of type UIComponent, although the 
	 * element may be set, this variable will be null since it
	 * is not a UIComponent.</p>
	 */
	public var host:UIComponent;
	
	//--------------------------------------------------------------------------
	//
	//  SkinPartAlias :: Variables
	//
	//--------------------------------------------------------------------------
		
	[SkinPartAlias]
	
	/**
	 * The label display in the Button component.
	 */
	public var labelDisplay:TextBase;
	
	[SkinPartAlias]
	
	/**
	 * The text display in the TextInput component.
	 */
	public var textDisplay:TextInput;	
	
	//--------------------------------------------------------------------------
	//
	//  Constructor
	//
	//--------------------------------------------------------------------------
	
	/**
	 * Constructor.
	 */
	public function HelloWorldBehavior()
	{
		super();
	}
	
	/**
	 * Handles the host.ROLL_OVER event dispatched from the host.
	 */
	component_handler function rollOverHandler(event:MouseEvent):void
	{
		if (labelDisplay)
			labelDisplay.text = "Hello World!";
		if (textDisplay)
			textDisplay.text = "Hello World!";			
	}
	
	/**
	 * Handles the host.ROLL_OUT event dispatched from the host.
	 */
	component_handler function rollOutHandler(event:MouseEvent):void
	{
		if (labelDisplay)
			labelDisplay.text = "Roll over me!";		
		if (textDisplay)
			textDisplay.text = "Roll over me!";
	}	
}
}